export default {
	common: {
		baseUrl: "http://101.200.167.127:8111/api",
		data: {},
		header: {
			// "content-type": "application/json",
			"token": uni.getStorageSync('token') || "",
		},
		method: "GET"
	},
	request(options={}) {
		uni.showLoading({
			title: '加载中'
		})
		options.url = this.common.baseUrl + options.url;
		options.data = options.data || this.common.data;
		options.header = options.header || this.common.header;
		options.method = options.method || this.common.method;
		return new Promise((res,rej) => {
			uni.request({
				...options,
				success: (result)=> {
					setTimeout(()=>{
						uni.hideLoading()
					},200)
					if(result.data.status == 200) {
						return res(result.data)
					} else {
						if(result.data.status == 401) {
							uni.removeStorageSync('token')
							uni.removeStorageSync('shopId')
							uni.navigateTo({
								url: '/pages/login'
							})
						}
						return rej(result.data)
					}
				}
			})
		})
	}
}